/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package eroshetta;

import java.util.List;

/**
 *
 * @author Mouaz
 */
public class DrugPresPanel extends javax.swing.JPanel {

    /**
     * Creates new form DrugPresPanel
     */
    public DrugPresPanel() {
        initComponents();
    }
     Drugs panelDrug;
     Prescriptions  panelPrescription;
     Eroshetta e;
    public DrugPresPanel(Drugs d ,Prescriptions p , Eroshetta e) {
        initComponents();
        this.panelDrug = d;
        this.panelPrescription = p;
        this.e =e;
        if(d.getTradeName() != null){
        this.setBorder(javax.swing.BorderFactory.createTitledBorder(d.getTradeName()));
//        this.duration.addItem("1 day");
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jCheckBox1 = new javax.swing.JCheckBox();
        jCheckBox2 = new javax.swing.JCheckBox();
        jCheckBox3 = new javax.swing.JCheckBox();
        jButton1 = new javax.swing.JButton();
        jCheckBox4 = new javax.swing.JCheckBox();
        jCheckBox5 = new javax.swing.JCheckBox();
        jCheckBox6 = new javax.swing.JCheckBox();
        duration = new javax.swing.JComboBox();

        setBorder(javax.swing.BorderFactory.createTitledBorder("Drug Name"));
        setAutoscrolls(true);
        setMaximumSize(new java.awt.Dimension(3000, 3000));
        setMinimumSize(new java.awt.Dimension(0, 0));

        jCheckBox1.setText("Before meal");
        jCheckBox1.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jCheckBox1StateChanged(evt);
            }
        });
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        jCheckBox2.setText("After meal");
        jCheckBox2.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jCheckBox2StateChanged(evt);
            }
        });
        jCheckBox2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox2ActionPerformed(evt);
            }
        });

        jCheckBox3.setText("Bed time");
        jCheckBox3.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jCheckBox3StateChanged(evt);
            }
        });

        jButton1.setText("X");
        jButton1.setToolTipText("Remove the Drug from List");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jCheckBox4.setText("Three times");
        jCheckBox4.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jCheckBox4StateChanged(evt);
            }
        });

        jCheckBox5.setText("Twice");
        jCheckBox5.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jCheckBox5StateChanged(evt);
            }
        });

        jCheckBox6.setText("Once");
        jCheckBox6.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jCheckBox6StateChanged(evt);
            }
        });
        jCheckBox6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox6ActionPerformed(evt);
            }
        });

        duration.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "One day", "Three days", "One week", "Two weeks","Three weeks", "One Months", "Two months", "Three months","Six month", "Nine month" }));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jCheckBox1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jCheckBox2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCheckBox3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 36, Short.MAX_VALUE)
                .addComponent(jButton1))
            .addGroup(layout.createSequentialGroup()
                .addComponent(jCheckBox6)
                .addGap(8, 8, 8)
                .addComponent(jCheckBox5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCheckBox4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(duration, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCheckBox1)
                    .addComponent(jCheckBox3)
                    .addComponent(jCheckBox2)
                    .addComponent(jButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCheckBox6)
                    .addComponent(jCheckBox4)
                    .addComponent(jCheckBox5)
                    .addComponent(duration, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jCheckBox1ActionPerformed
public void changeCheck1(List <DrugPresPanel>drugsPanels){
    for(int i=0;i<drugsPanels.size();i++){
        if(drugsPanels.get(i).panelDrug.getId()==this.panelDrug.getId()){
           drugsPanels.get(i).jCheckBox1.setSelected(this.jCheckBox1.isSelected()); 
           return;
        }
    }
}
public void changeCheck2(List <DrugPresPanel>drugsPanels){
    for(int i=0;i<drugsPanels.size();i++){
        if(drugsPanels.get(i).panelDrug.getId()==this.panelDrug.getId()){
           drugsPanels.get(i).jCheckBox2.setSelected(this.jCheckBox2.isSelected()); 
           return;
        }
    }
}
public void changeCheck3(List <DrugPresPanel>drugsPanels){
    for(int i=0;i<drugsPanels.size();i++){
        if(drugsPanels.get(i).panelDrug.getId()==this.panelDrug.getId()){
           drugsPanels.get(i).jCheckBox3.setSelected(this.jCheckBox3.isSelected()); 
           return;
        }
    }
}
public void changeCheck4(List <DrugPresPanel>drugsPanels){
    for(int i=0;i<drugsPanels.size();i++){
        if(drugsPanels.get(i).panelDrug.getId()==this.panelDrug.getId()){
           drugsPanels.get(i).jCheckBox4.setSelected(this.jCheckBox4.isSelected()); 
           return;
        }
    }
}
public void changeCheck5(List <DrugPresPanel>drugsPanels){
    for(int i=0;i<drugsPanels.size();i++){
        if(drugsPanels.get(i).panelDrug.getId()==this.panelDrug.getId()){
           drugsPanels.get(i).jCheckBox5.setSelected(this.jCheckBox5.isSelected());
           return;
        }
    }
}
public void changeCheck6(List <DrugPresPanel>drugsPanels){
    for(int i=0;i<drugsPanels.size();i++){
        if(drugsPanels.get(i).panelDrug.getId()==this.panelDrug.getId()){
           drugsPanels.get(i).jCheckBox6.setSelected(this.jCheckBox6.isSelected());
           return;
        }
    }
}
    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
this.e.DrugsInPrescription.removeAll();
this.e.DrugsInPrescription.setVisible(false);
this.e.DrugsInPrescription.setVisible(true);
        this.e.removeDrug(this.panelDrug,this);

        this.setVisible(false);
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1MouseClicked

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jCheckBox6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox6ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jCheckBox6ActionPerformed

    private void jCheckBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jCheckBox2ActionPerformed

    private void jCheckBox1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jCheckBox1StateChanged

        this.changeCheck1(Eroshetta.drugsPanels);// TODO add your handling code here:
    }//GEN-LAST:event_jCheckBox1StateChanged

    private void jCheckBox2StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jCheckBox2StateChanged
        this.changeCheck2(Eroshetta.drugsPanels);        // TODO add your handling code here:
    }//GEN-LAST:event_jCheckBox2StateChanged

    private void jCheckBox3StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jCheckBox3StateChanged
        this.changeCheck3(Eroshetta.drugsPanels);        // TODO add your handling code here:
    }//GEN-LAST:event_jCheckBox3StateChanged

    private void jCheckBox6StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jCheckBox6StateChanged
        this.changeCheck4(Eroshetta.drugsPanels);        // TODO add your handling code here:
    }//GEN-LAST:event_jCheckBox6StateChanged

    private void jCheckBox5StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jCheckBox5StateChanged
        this.changeCheck5(Eroshetta.drugsPanels);        // TODO add your handling code here:
    }//GEN-LAST:event_jCheckBox5StateChanged

    private void jCheckBox4StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jCheckBox4StateChanged
        this.changeCheck6(Eroshetta.drugsPanels); 
        // TODO add your handling code here:
    }//GEN-LAST:event_jCheckBox4StateChanged

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JComboBox duration;
    private javax.swing.JButton jButton1;
    public javax.swing.JCheckBox jCheckBox1;
    public javax.swing.JCheckBox jCheckBox2;
    public javax.swing.JCheckBox jCheckBox3;
    public javax.swing.JCheckBox jCheckBox4;
    public javax.swing.JCheckBox jCheckBox5;
    public javax.swing.JCheckBox jCheckBox6;
    // End of variables declaration//GEN-END:variables
}
